package com.steven.ourcontest.information.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.steven.ourcontest.R
import com.steven.ourcontest.app.AppRouter
import com.steven.ourcontest.information.bean.SchoolName
import com.steven.ourcontest.utils.Identity

class SearchSchoolAdapter(
    private val context: Context,
    private val identity: Identity
) : RecyclerView.Adapter<ViewHolder>() {

    private val itemData by lazy {
        arrayListOf<SchoolName>()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
        val inflater =
            LayoutInflater.from(context).inflate(R.layout.item_school_name, parent, false)
        return ViewHolder(inflater)
    }

    override fun getItemCount(): Int {
        return itemData.size
    }

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.tv_school_name?.text = itemData[position].schoolName
        holder.itemView.setOnClickListener {
            AppRouter.gotoConfirmStudentInfoActivity(context, itemData[position].schoolName,identity)
        }
    }

    fun submitData(data: List<SchoolName>) {
        itemData.clear()
        itemData.addAll(data)
        notifyDataSetChanged()
    }
}

class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    var tv_school_name: TextView? = itemView.findViewById(R.id.tv_school_name)
}